<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<script>var ctx="${ctx}";</script>
<div class="form-horizontal" role="form" >
    <input type="hidden" id="token" name="token" value="<%=request.getAttribute("token") %>" />
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">标题:</label>
        <div class="col-md-9">
        	 <input id="title" value="${announce.title}" data-check="require:true;code:^[a-zA-Z0-9\u4e00-\u9fa5]{1,30};message:不能为空" type="text" placeholder="标题" class="form-control" name="title"/>
        </div>
    </div>
    	<div class="form-group">
	 	    <label class="col-md-3 col-sm-3 control-label">图片:</label>
	        <div class="col-md-9">
	        	 <input class="fileInput" id="imageUploadify" type="file" name="file" accept="image/*"/>
	        	 <div class="imageUploadify">   
					<c:if test="${not empty(announce.image)}">
					<c:forEach items="${fn:split(announce.image,',')}" var="i">
						<img src="${i}" style="width: 60px;height: 60px">
					</c:forEach>
					</c:if>
				 </div>
	        </div>
	   </div>
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">链接地址:</label>
        <div class="col-md-9">
        	 <input id="url" value="${announce.url}"  type="text" placeholder="链接地址" class="form-control" name="url"/>
        </div>
    </div>
    <div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">分类:</label>
        <div class="col-md-9">
        	<select id="typeId" placeholder="选择分类" class="chosen-select full-width" tabindex="4">
			
			</select>
        </div>
    </div>
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">作者:</label>
        <div class="col-md-9">
        	 <input id="author" value="${announce.author}"  type="text" placeholder="作者" class="form-control" name="author"/>
        </div>
    </div>
	<div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">出处:</label>
        <div class="col-md-9">
        	 <input id="source" value="${announce.source}"  type="text" placeholder="出处" class="form-control" name="source"/>
        </div>
    </div>

<!-- 	<div class="form-group"> -->
<!--  	    <label class="col-md-3 col-sm-3 control-label">状态:</label> -->
<!--         <div class="col-md-9"> -->
<%--         	 <input id="enabled" value="${announce.enabled}"  type="text" placeholder="状态" class="form-control" name="enabled"/> --%>
<!--         </div> -->
<!--     </div> -->

    <div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">状态：</label>
        <div class="col-md-9">
        	 	<input type="checkbox" class="js-switch" name="enabled" checked="checked"/>
        </div>
    </div>
    <div class="form-group">
 	    <label class="col-md-3 col-sm-3 control-label">内容:</label>
        <div class="col-md-9">
        	 <script type="text/plain" id="editor"></script>
        </div>
    </div>
<!-- 	<div class="form-group"> -->
<!--  	    <label class="col-md-3 col-sm-3 control-label">分类id:</label> -->
<!--         <div class="col-md-9"> -->
<%--         	 <input id="typeId" value="${announce.typeId}"  type="text" placeholder="分类id" class="form-control" name="typeId"/> --%>
<!--         </div> -->
<!--     </div> -->
</div>
<script>
$(function(){
	//UE.getEditor('editor2').destroy();
	UE.delEditor("editor");
	 ue=UE.getEditor('editor',{
	    //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
	    toolbars: [[
		   'fullscreen', 'source', '|', 'undo', 'redo', '|',
	       'bold', 'italic', 'underline', 'fontborder', 'removeformat', 'formatmatch', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist',
	       'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
	       'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
	       'indent',
	       'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
	       'link', 'unlink','simpleupload', 'insertimage','insertvideo'
		 ]],
	     //关闭字数统计
	     wordCount:false,
	     initialFrameHeight:200,
	     //关闭elementPath
	     elementPathEnabled:false
	})
})
</script>
<script>

$(function(){
	jQuery.checkall(false);
})
			var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
			elems.forEach(function(html) {
				var switchery = new Switchery(html);
			});	 
			var typeId="${departmentId}";
			$("#typeId").chosen({ width: '100%' });
			
			$.ajax({  
				url:'${ctx}/announceType/list',  		 					
				data:{						
				},   
				type: 'POST',
				dataType:'json',  
				success:function(response){
					if(response.code==0){
						var html=[];
						var data=response.data||[];
						for(var i=0;i<data.length;i++){
							html.push('<option value="'+data[i].id+'" ');
							html.push('>'+data[i].name+'</option>');
						}
						$("#typeId").append(html.join(""));
						$("#typeId").trigger("chosen:updated");
					}
				}  
		     });
			

			$("#imageUploadify").uploadify({
				'buttonImage':'${ctx}/static/js/plugins/uploadify/uploadify-button.png',
			    'swf': '${ctx}/static/js/plugins/uploadify/uploadify.swf',
			    'uploader':'${ctx}/file/uploadOss',
			    'multi':false,
			    'onFallback' : function() {//检测FLASH失败调用 
			    	alert("您未安装FLASH控件，无法上传图片！请安装FLASH控件后再试。");  
			    },  
			    'onUploadSuccess':function(file, data, response){
			    	var jData = jQuery.parseJSON(data);
			        $(".imageUploadify").html("<img src=\""+jData.data+"\" style=\"width: 60px;height: 60px;padding-left:5px;\">");
				}
			});

</script>